#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    : __init__.py.py
@Author  : different && 道阻且长,行则将至 行而不辍,未来可期
@Time    : 2021/8/31 10:28
@Desc    :

"""


def get_or_create(session, model, **kwargs):
    instance = session.query(model).filter_by(**kwargs).first()
    if instance:
        return instance
    else:
        instance = model(**kwargs)
        session.add(instance)
        session.commit()
        return instance
